<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>title</title>
  <!--按顺序引入-->
  <script src="https://cdn.staticfile.org/react/16.8.4/umd/react.development.js"></script>
  <script src="https://cdn.staticfile.org/react-dom/16.8.4/umd/react-dom.development.js"></script>
  <script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
  <script src="../js/babel.min.js"></script>
  <script src="https://cdn.bootcdn.net/ajax/libs/prop-types/15.8.1/prop-types.js"></script>
  <style>
    body {
      width: 95vw;
      height: 80vh;
      background-color: #2b2b2b;
      color: wheat;
    }
  </style>
</head>
<body>
<div id="app"></div>

<script type="text/babel">
  // refs有三种写法
  /*
  * 1.ref="input1" 字符串写法 不推荐
  * 2.回调函数写法 ref={currentNode => this.input2 = currentNode} 或 ref={this.saveInput} 内联和类绑定
  * 3.createRef   myRef = React.createRef() ref={this.myRef} 节点会自动白存到myRef容器中
  */
  class Demo extends React.Component {
    state = {isHot: false}
    // createRef写法 专用的 只能存一个 要保存多个需要创建多个容器
    myRef = React.createRef()

    render() {
      return (
        <div>
          <input ref="input1" type="text" placeholder={'今天天气很'+(this.state.isHot?'炎热':'不炎热')}/>
          <button onClick={this.showData}>点击</button>
          {/*<input ref={currentNode => this.input2 = currentNode} onBlur={this.showData2} type="text" placeholder="失去焦点提示数据"/>*/}
          <input ref={this.saveInput} onBlur={this.showData2} type="text" placeholder="失去焦点提示数据"/>
          <input ref={this.myRef} onClick={this.showData3} type="text" placeholder="createRef"/>
        </div>
      )
    }

    showData = () => {
      console.log(this.refs['input1'].value)
      this.setState({isHot: !this.state.isHot})
    }
    showData2 = () => {
      console.log(this['input2'].value)
    }
    showData3 = () => {
      console.log(this.myRef.current.placeholder)
    }
    saveInput = (currentNode) => {
      this.input2 = currentNode
    }
  }

  ReactDOM.render(<Demo />, document.getElementById('app'))
</script>
</body>
</html>
